package com.steam.xbcc.controller;

import com.steam.xbcc.doc.CourseDoc;
import com.steam.xbcc.dto.CourseEsDto;
import com.steam.xbcc.result.JSONResult;
import com.steam.xbcc.result.PageList;
import com.steam.xbcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseEsController {

    @Autowired
    private ICourseEsService courseEsService;

    @PreAuthorize("hasAuthority('es:saveCourse')")
    @RequestMapping(value="/saveCourseEs", method= RequestMethod.POST)
    public JSONResult saveCourseEs(@RequestBody CourseDoc courseDoc){
        courseEsService.save(courseDoc);
        return JSONResult.success();
    }

    @RequestMapping(value="/search", method= RequestMethod.POST)
    public JSONResult search(@RequestBody CourseEsDto courseEsDto){
        PageList<CourseDoc> pageList = courseEsService.search(courseEsDto);
        return JSONResult.success(pageList);
    }
}
